#!/bin/bash
#+-------------------------------------------------------------+
#| Program: flashinstall                                       |
#| Version: 1.0.0                                              |
#| Date: 04-20-2018                                            |
#| Autor: Francisco Iago Lira Passos                           |
#| Email: iagolirapassos@gmail.com                             |
#| Bugs report: https://notabug.org/iagolira/flashinstall.git  |
#| ssh: git@notabug.org:iagolira/flashinstall.git              |
#+-------------------------------------------------------------+

sitea="https://get.adobe.com/br/flashplayer/?Lang=Brazilian"
sited="https://fpdownload.adobe.com/pub/flashplayer/pdc/"
agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
version="$(wget --user-agent=$agent -qO - $sitea <<< Versão | grep -E Versão | sed 's/[^0-9.]//g')"
amd="https://fpdownload.adobe.com/pub/flashplayer/pdc/$version/"
i386="https://fpdownload.adobe.com/pub/flashplayer/pdc/$version/"

install(){
    #NPAPI
	if [ $1 == 1  ]; then
        case $2 in
        "x86_64")
                echo "Installing (x86_64)..."
                v64="flash_player_npapi_linux.x86_64.tar.gz"
                pst=`echo $v64 | sed 's/.tar.gz//g'`
                mkdir $pst
                wget --show-progress $amd/$v64 -O $v64
                tar zxvf $v64 -C $pst
                cd $pst
                cp -r usr/* /usr
                cp libflashplayer.so /usr/lib/mozilla/plugins/
                cd ..
                rm -rf $pst
                ;;
          "i386")
                echo "Installing (i386)..."
                v32="flash_player_npapi_linux.i386.tar.gz"
                pst=`echo $v32 | sed 's/.tar.gz//g'`
                mkdir $pst
                wget --show-progress $amd/$v32 -O $v32
                tar zxvf $v32 -C $pst
                cd $pst
                cp -r usr/* /usr
                cp libflashplayer.so /usr/lib/mozilla/plugins/
                cd ..
                rm -rf $pst
                ;;
        *) echo "Invalid option!" ;;
        esac
    #PPAPI
	elif [ $1 == 2 ]; then
        case $2 in
        "x86_64")
                [ -d /usr/lib/adobe-flashplugin/ ] || mkdir /usr/lib/adobe-flashplugin/
                echo "Installing (x86_64)..."
                v64="flash_player_ppapi_linux.x86_64.tar.gz"
                wget --show-progress $amd/$v64 -O $v64
                tar zxvf $v64 -C /usr/lib/adobe-flashplugin/
                ;;
          "i386")
                [ -d /usr/lib/adobe-flashplugin/ ] || mkdir /usr/lib/adobe-flashplugin/
                echo "Installing (i386)..."
                v32="flash_player_npapi_linux.i386.tar.gz"
                wget --show-progress $amd/$v32 -O $v32
                tar zxvf $v32 -C /usr/lib/adobe-flashplugin/
                ;;
        *) echo "Invalid option!" ;;
        esac

	fi
}

menu(){
varch=`uname -m`

    if [ $varch = "x86_64" ]; then
        arch="64 bit"
    elif [ $varch = "i386" ]; then
        arch="32 bit"
    fi

    echo "
    +---- Adobe Flash Player ----+
    | Version $version         |
    +----------------------------+
    |                            |
    |    Architecture $arch     |
    |                            |
    +----------------------------+
    |    Adobe Version           |                             
    |                            |
    |    [1] -> NPAPI            |
    |    [2] -> PPAPI            |
    +----------------------------+
    "
    read -n 1 -p "Enter the desired option: " option
    install $option $varch
}

menu

